﻿using System;
using System.Linq;
using System.Threading.Tasks;
using Abp.Domain.Entities;
using Abp.EntityFramework;
using Abp.EntityFramework.Repositories;
using GN.Pay.Core.Repositories;
using System.Data.Entity.Infrastructure;
using GN.EntityFramework.Repositories;

namespace GN.Pay.EntityFramework.Repositories
{
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    /// <typeparam name="TPrimaryKey"></typeparam>
    public abstract class PayRepositoryBase<TEntity, TPrimaryKey> : GNEfRepositoryBase<PayDbContext, TEntity, TPrimaryKey>, IPayRepository<TEntity, TPrimaryKey>
        where TEntity : class, IEntity<TPrimaryKey>
    {
        protected PayRepositoryBase(IDbContextProvider<PayDbContext> dbContextProvider)
            : base(dbContextProvider)
        {
        }

        /// <summary>
        /// 设置实体状态
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="entityState">实体状态</param>
        public void SetEntityState(TEntity entity, int entityState)
        {
            if (entity != null)
            {
                var entry = this.Context.Entry(entity);
                entry.State = (System.Data.Entity.EntityState)entityState;
            }
        }       
    }

    public abstract class PayRepositoryBase<TEntity> : PayRepositoryBase<TEntity, int>
        where TEntity : class, IEntity<int>
    {
        protected PayRepositoryBase(IDbContextProvider<PayDbContext> dbContextProvider)
            : base(dbContextProvider)
        {

        }

        //do not add any method here, add to the class above (since this inherits it)
    }
}
